package circularGameLosers;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public int[] circularGameLosers(int n, int k) {
        int[] marks = new int[n]; // 标记数组
        int i = 0; //第i轮 传给(index+i*k)%n
        int prevIndex = 0;// 上一轮球在谁手里
        while (true){
            int index = (prevIndex+i*k)%n; // 这一轮球在哪里
            marks[index]++;
            if(marks[index] == 2){
                break;
            }
            i++;
            prevIndex = index;
        }
        List<Integer> list = new ArrayList<>();
        for (int j = 0; j < marks.length; j++) {
            if(marks[j]==0){
                list.add(j);
            }
        }
        int[] ans = new int[list.size()];
        for (int j = 0; j < list.size(); j++) {
            ans[j] = list.get(j);
        }
        return ans;
    }
}
